package app.util.image.action
{
	import app.util.*;
	
	import flash.display.*;
	import flash.filters.*;
	import flash.geom.*;
	
	public class LomoAction extends AbstractAction
	{
		private var contrast:Number;
		private var distance:Number;
		
		public function setValue(contrast:Number,distance:Number):LomoAction
		{
			this.contrast = contrast;
			this.distance = distance;
			return this;
		}
		
		public override function getDescription():String
		{
			return "LOMO (" + this.contrast.toFixed(0) + ", " + this.distance.toFixed(0) + ")";
		}
		
		public override function getActionedBitmapData():BitmapData
		{
			var old:BitmapData = Mediator.getCurrentBitmapData();
			var ret:BitmapData = old.clone();
			
			var matrix:ColorMatrix = new ColorMatrix();
			matrix.adjustContrast(contrast);
			var colorMatrixFilter:ColorMatrixFilter = new ColorMatrixFilter(matrix.matrix);
			var shadowFilter:DropShadowFilter = new DropShadowFilter();
			shadowFilter.inner = true;
			shadowFilter.distance = 4.0;
			shadowFilter.strength = this.distance;
			shadowFilter.alpha = 0.7;
            shadowFilter.quality = 3;
            shadowFilter.angle = 45;
            shadowFilter.blurX = ret.width / 3;
            shadowFilter.blurY = ret.height / 3;
			
			ret.applyFilter(ret, ret.rect, new Point(0, 0), colorMatrixFilter);
			ret.applyFilter(ret, ret.rect, new Point(0, 0), shadowFilter);
			return ret;
		}	
	}
}